<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <meta http-equiv="X-UA-Compatible" content="ie=edge">
    <title>Document</title>
    <script>
    function Person(name,age){
        this.name=name;
        this.age=age;
        this.toString=function (){
            console.log("Person[name="+this.name+",age="+this.age+"]"); 
        }      
    }
    var per1=new Person("孙悟空",15);
    var per2=new Person("猪八戒",17);
    var per3=new Person("沙和尚",21);
    var arr=[per1,per2,per3];

    // for(var i=0;i<arr.length;i++){
    //     console.log(arr[i]);
    // }
    arr.forEach(function(a,b){
            console.log(b);
            console.log(a.toString);
    });


    </script>
</head>
<body>
    
</body>
</html>